const app = getApp()
import {
  ajaxGetRanks,
} from '../../api/my'

Page({
  /**
   * 页面的初始数据
   */
  data: {
    //自定义导航高度
    customNavHeight: app.globalData.customNavInfo.navHeight,
    baseURL: app.globalData.config.baseURL,
    currentTab: 'weekly', // 默认显示每周排行榜
    type:'all',
    dateType:1,
    dateTab:'weekly',
    ranks: [

    ]
  },


  switchTab: function(e) {
    this.setData({
      dateTab: e.currentTarget.dataset.tab
    });
    if (this.data.dateTab === 'weekly') {
      this.setData({
        dateType: 1
      });
    }else if (this.data.dateTab === 'monthly') {
      this.setData({
        dateType: 2
      });
    }else if (this.data.dateTab === 'year') {
      this.setData({
        dateType: 3
      });
    }
    this.updateRanks();
  },

  switchTypeTab:function(e) {
    this.setData({
      type: e.currentTarget.dataset.tab
    });
    this.updateRanks();
  },

  updateRanks:function(){
    let params = {type:this.data.type === 'all'?'':this.data.type,dateType:this.data.dateType};
    console.log(params)
    ajaxGetRanks(params).then(resp=>{
       if (resp.code === 0){
           resp.data;
          this.setData({
            "ranks":resp.data
          })
       }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.updateRanks();
  },

  getMenuButtonBound() {
    let stateHeight = 0; //  接收状态栏高度
    const navHeight = wx.getMenuButtonBoundingClientRect().height; //  获取胶囊高度
    let top = 0;
    wx.getSystemInfo({
      success(res) {
        stateHeight = res.statusBarHeight;
      },
    });
    top = wx.getMenuButtonBoundingClientRect().top - stateHeight; //  获取top值

    console.log(stateHeight);
    console.log(top);
    this.setData({
      // navHeight: navHeight + top * 2, //  导航栏高度
      navHeight, //  导航栏高度
      stateHeight: stateHeight + top, //  状态栏高度
    });
  },

// 返回
  goBack: function () {
    wx.switchTab({
      url: "/pages/my/index"
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getMenuButtonBound();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  }
})